package sort;

public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = new int[]{9,1,5,8,3,7,4,6,2};
        BubbleSort sort = new BubbleSort(arr);
        sort.printf();
        sort.sort();
        sort.printf();
    }

    private int[] array;

    public BubbleSort(int[] array) {
        this.array = array;
    }

    public void sort(){
     boolean flag = true;
        for (int i = 1; i < this.array.length && flag; i++) {
            flag = false;
            for (int j = 0; j < (this.array.length-i); j++) {
                if (array[j+1]<array[j]){
                    int temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                    flag = true;
                }
            }
        }
        /* return  this.array;*/

    }

    public void printf(){
        for (int i = 0; i < this.array.length; i++) {
            System.out.println(array[i]);
        }
    }
}
